#define _CRT_SECURE_NO_WARNINGS 1
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

const int N = 1e6 + 10;

long long n,m;
long long row[N], col[N];

int main() 
{
    scanf("%lld %lld", &n,&m);
    //long long arr[n][m];
    vector<vector<long long>> arr(n, vector<long long>(m));
    for (int i = 0; i < n; i++) 
    {
        for (int j = 0; j < m; j++) 
        {
            scanf("%ld", &arr[i][j]);
            row[i] += arr[i][j];
            col[j] += arr[i][j];
        }
    }

    for (int i = 0; i < n; i++) 
    {
        for (int j = 0; j < m; j++) 
        {
            printf("%ld ", row[i] + col[j] - arr[i][j]);
        }
        cout << endl;
    }
    return 0;
}
//#include <iostream>
//#include <string>
//
//using namespace std;
//
//int main()
//{
//    string s;
//    cin >> s;
//
//    for (int i = 0; i < s.size(); i++)
//    {
//        if (s[i] % 2 == 0) s[i] = '0';
//        else s[i] = '1';
//    }
//
//    cout << stoi(s) << endl;
//    return 0;
//}